/*
 * @Description:
 * @Author: mmzhang
 * @Date: 2022-11-14 10:12:04
 * @LastEditTime: 2023-01-11 09:07:46
 */
import dt from '@dt/dt'
import toolMgr from '@/biz/base/tool.js'
import houseOpt from '@/biz/option/house.js'

let orgs = []

function organization() {
  return toolMgr.organization(2).then((res) => {
    orgs = res
    return res
  })
}

function getCooperationType() {
  // let list = dt.dictInfo().channelType.reduce((arr, {
  //   children
  // }) => {
  //   if (children) {
  //     for (let item of children) {
  //       if (!arr.find(i => i.key == item.key)) {
  //         arr.push({ key: item.key, value: item.value })
  //       }
  //     }
  //   }
  //   return arr
  // }, [{
  //   key: '',
  //   value: '无'
  // }])
  return {
    key: 'cooperationType',
    title: '合作类型',
    select: {
      options: dt.dictInfo().cooperationTypeFinal
    }
  }
}

function options(_this) {
  return [
    {
      key: 'companyId',
      title: '所属公司',
      load: (o) => {
        organization().then((res) => {
          o.cascader.options = res
        })
      },
      cascader: {
        options: orgs
      }
    },
    houseOpt.create({
      to: (info) => {
        return {
          buildingId: info.housesId,
          buildingName: info.housesName
        }
      }
    }),
    {
      key: 'roomCode',
      title: '所属房源',
      placeholder: '请输入房源名称',
      input: {}
    }
  ]
}

export default {
  options,
  getCooperationType
}
